#pragma once

#include "noiseutils.h"

struct HeightMapTile
{
	int Height;
	bool Mod = false;
};

class HeightMap
{	
public:
	HeightMap()
	{
		m_size = GameConfig::Get().MapSize;
		Tile.resize(m_size);
		for ( int i = 0; i < m_size; i++ )
			Tile[i].resize(m_size);
	}

	void Init(int lineH)
	{
		m_lineH = lineH;
		
		noise::module::Perlin myModule;
		myModule.SetOctaveCount(6);
		myModule.SetFrequency(0.5);
		myModule.SetPersistence(0.5);
		utils::NoiseMap heightMap;
		utils::NoiseMapBuilderPlane heightMapBuilder;
		heightMapBuilder.SetSourceModule(myModule);
		heightMapBuilder.SetDestNoiseMap(heightMap);
		heightMapBuilder.SetDestSize(m_size, m_size);
		heightMapBuilder.SetBounds(0.0, 5.0, 0.0, 5.0);
		heightMapBuilder.Build();

		for ( int x = 0; x < m_size; x++ )
		{
			for ( int y = 0; y < m_size; y++ )
			{
				float th = heightMap.GetValue(x, y);
				sint h = 0;
	
				if ( th >= 1.0f )
					h = -3;
				else if ( th < 1.0f && th >= 0.8f )
					h = -2;
				else if ( th < 0.8f && th >= 0.6f )
					h = -1;
				else if ( th > -0.9f && th <= -0.8f )
					h = 1;
				else if ( th > -1.0f && th <= -0.9f )
					h = 2;
				else if ( th <= -1.0f )
					h = 2;				

				Tile[x][y].Height = m_lineH + h;
			}
		}
	}

	std::vector<std::vector<HeightMapTile>> Tile;

private:
	int m_size;
	int m_lineH;
};